<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-input
        placeholder="请输入内容"
        v-model="params.query"
        class="input-with-select"
        clearable
        @clear="inputClear"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '1'" type="success">
              已付款
            </el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="openeditDialog(scope.row)"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="openShowProgressDialog(scope.row.order_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pagenum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 编辑订单 -->
    <el-dialog
      title="修改地址"
      :visible="editDialogVisible"
      width="50%"
      @close="editdialogClose"
    >
      <el-form
        ref="AdressFormRef"
        :model="AdressForm"
        label-width="100px"
        :rules="AdressFormRules"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            :options="cityData"
            v-model="AdressForm.address1"
            :props="props"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="AdressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false">
          确 定
        </el-button>
      </span>
    </el-dialog>
    <!-- 显示物流信息 -->
    <el-dialog
      title="物流信息"
      :visible="showProgressdialogVisible"
      width="50%"
    >
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(activity, index) in showProgress"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showProgressdialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @showProgressdialogVisible="dialogVisible = false"
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import cityData from './citydata'
export default {
  created() {
    this.getOrderList()
  },
  data() {
    return {
      params: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      orderList: [],
      editDialogVisible: false,
      AdressForm: { address1: [], address2: '' },
      AdressFormRules: {
        address1: {
          required: true,
          message: '请选择省市县/区',
          trigger: 'blur'
        },
        address2: { required: true, message: '请输入详细地址', trigger: 'blur' }
      },
      cityData,
      props: {
        expandTrigger: 'hover',
        value: 'value',
        label: 'label',
        children: 'children'
      },
      showProgressdialogVisible: false,
      showProgress: []
    }
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get(`orders`, {
        params: this.params
      })
      if (res.meta.status !== 200) {
        this.$message.error('获取订单列表失败')
        return
      }
      this.total = res.data.total
      // console.log(res.data.goods)
      this.orderList = res.data.goods
    },
    inputClear() {
      this.params.query = ''
      this.getOrderList()
    },
    handleSizeChange(size) {
      this.params.pagesize = size
      this.getOrderList()
    },
    handleCurrentChange(page) {
      this.params.pagenum = page
      this.getOrderList()
    },
    openeditDialog(row) {
      this.editDialogVisible = true
    },
    editdialogClose() {
      this.$refs.AdressFormRef.resetFields()
      this.editDialogVisible = false
    },
    async openShowProgressDialog(id) {
      const { data: res } = await this.$http.get(`/kuaidi/804909574412544580`)
      if (res.meta.status !== 200) {
        this.$message.error('获取物流信息失败')
        return
      }
      this.showProgress = res.data
      this.showProgressdialogVisible = true
    }
  }
}
</script>
<style lang="less" scope></style>
